#include "headfile.h"
#include "isr.h"

uint64_t count=0;
extern uint8_t master_status;
extern struct buffer uart_buff;

extern hw_timer_t *timer;
extern hw_timer_t *timer2;

// 接收
void task_receive(void *task1)
{
    timer_init();
    int temp;
    uint8_t receive_data;  // 接收到的数据
    while(true)
    {
        if(master_status==SEND)
        {
            static uint8_t order=0;
            if(order==0)
            {
                ask_for_data();
                order++;
            }                                 
            else
            {
                ask_for_unit();
                order=0;
            }
            master_status = RECEIVE;
            timerRestart(timer2);  // 接收定时        
        }
        else if(master_status==RECEIVE)     
        {
            temp = Serial2.read();
            if(temp != -1)  // 接收到数据
            {                           
                receive_data = (uint8_t)temp;
                write_buffer(&uart_buff,&receive_data);               
                timerRestart(timer);// 打开定时器 
            }                                
        }
    }
}

